/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package loginview;



import java.awt.event.KeyEvent;
import java.io.ByteArrayOutputStream;
import java.sql.*;
import javax.swing.*;
import net.proteanit.sql.DbUtils;
import java.text.*;
import java.io.File;
import java.io.FileInputStream;
import static java.lang.Thread.sleep;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;

public class EmployerViewFrame extends javax.swing.JFrame {
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;
    /**
     * Creates new form EmployerViewFrame
     */
    public EmployerViewFrame() {
        initComponents();
        conn = JavaConnect.ConnecrDb();
        Update_table();
        CurrentDate();
     
    }
private void Update_table(){
    String sql = "SELECT * FROM Employee";
    try{
    pst = conn.prepareStatement(sql);
    rs = pst.executeQuery();
    tableEmployee.setModel(DbUtils.resultSetToTableModel(rs));
    }
    catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
    }
    finally {
    try{
    rs.close(); 
    pst.close(); }
    catch(Exception e) { } }
}
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tableEmployee = new javax.swing.JTable();
        clearButton = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        homeButton = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        lbl_date = new javax.swing.JLabel();
        lbl_time = new javax.swing.JLabel();
        saveButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        updateButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        txtEmpName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtEmpAddrsNum = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtEmpTelNum = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtEmpMachineName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtEmpSurname = new javax.swing.JTextField();
        txtEmpMachineID = new javax.swing.JTextField();
        txtEmpID = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        printButton = new javax.swing.JButton();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        image = new javax.swing.JLabel();
        txtPath = new javax.swing.JTextField();
        attachImage = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        txtSearch = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setLocation(new java.awt.Point(120, 20));
        setPreferredSize(new java.awt.Dimension(1050, 765));

        tableEmployee.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tableEmployee.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableEmployeeMouseClicked(evt);
            }
        });
        tableEmployee.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tableEmployeeKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tableEmployeeKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tableEmployee);

        clearButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/loginview/Actions-edit-clear-icon.png"))); // NOI18N
        clearButton.setText("Clear");
        clearButton.setMaximumSize(new java.awt.Dimension(80, 28));
        clearButton.setMinimumSize(new java.awt.Dimension(65, 28));
        clearButton.setPreferredSize(new java.awt.Dimension(80, 28));
        clearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButtonActionPerformed(evt);
            }
        });

        jToolBar1.setRollover(true);
        jToolBar1.setMaximumSize(new java.awt.Dimension(100, 50));
        jToolBar1.setPreferredSize(new java.awt.Dimension(100, 50));

        homeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/loginview/green-home-icon.png"))); // NOI18N
        homeButton.setText("Home");
        homeButton.setFocusable(false);
        homeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        homeButton.setMaximumSize(new java.awt.Dimension(75, 60));
        homeButton.setPreferredSize(new java.awt.Dimension(75, 60));
        homeButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        homeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                homeButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(homeButton);

        jLabel9.setMaximumSize(new java.awt.Dimension(700, 55));
        jLabel9.setPreferredSize(new java.awt.Dimension(700, 55));
        jToolBar1.add(jLabel9);

        lbl_date.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        lbl_date.setForeground(new java.awt.Color(51, 51, 51));
        lbl_date.setText("Date");
        lbl_date.setMaximumSize(new java.awt.Dimension(150, 55));
        lbl_date.setPreferredSize(new java.awt.Dimension(150, 55));
        jToolBar1.add(lbl_date);

        lbl_time.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        lbl_time.setForeground(new java.awt.Color(51, 51, 51));
        lbl_time.setText("Time");
        lbl_time.setMaximumSize(new java.awt.Dimension(150, 55));
        lbl_time.setPreferredSize(new java.awt.Dimension(150, 55));
        jToolBar1.add(lbl_time);

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/loginview/Actions-document-save-icon.png"))); // NOI18N
        saveButton.setText("Save");
        saveButton.setMaximumSize(new java.awt.Dimension(80, 28));
        saveButton.setPreferredSize(new java.awt.Dimension(80, 28));
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        deleteButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/loginview/trash-icon.png"))); // NOI18N
        deleteButton.setText("Delete");
        deleteButton.setMaximumSize(new java.awt.Dimension(85, 28));
        deleteButton.setPreferredSize(new java.awt.Dimension(85, 28));
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        updateButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/loginview/Button-Refresh-icon.png"))); // NOI18N
        updateButton.setText("Update");
        updateButton.setMaximumSize(new java.awt.Dimension(90, 28));
        updateButton.setPreferredSize(new java.awt.Dimension(90, 28));
        updateButton.setSize(new java.awt.Dimension(90, 28));
        updateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        txtEmpName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEmpNameActionPerformed(evt);
            }
        });

        jLabel4.setText("Machine name");

        jLabel1.setText("Employer ID");

        txtEmpTelNum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEmpTelNumActionPerformed(evt);
            }
        });

        jLabel5.setText("Machine ID");

        jLabel7.setText("Address number");

        jLabel2.setText("Name");

        jLabel6.setText("Telephone number");

        jLabel3.setText("Surname");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(26, 26, 26))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtEmpTelNum)
                    .addComponent(txtEmpID)
                    .addComponent(txtEmpName)
                    .addComponent(txtEmpSurname)
                    .addComponent(txtEmpMachineName)
                    .addComponent(txtEmpMachineID)
                    .addComponent(txtEmpAddrsNum))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmpID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmpName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmpSurname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmpMachineName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmpMachineID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmpTelNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEmpAddrsNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addContainerGap())
        );

        printButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/loginview/Actions-document-print-icon.png"))); // NOI18N
        printButton.setText("Print");
        printButton.setMaximumSize(new java.awt.Dimension(90, 28));
        printButton.setPreferredSize(new java.awt.Dimension(90, 28));
        printButton.setSize(new java.awt.Dimension(90, 28));
        printButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
        jDesktopPane1.setLayout(jDesktopPane1Layout);
        jDesktopPane1Layout.setHorizontalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDesktopPane1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(image, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                .addContainerGap())
        );
        jDesktopPane1Layout.setVerticalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDesktopPane1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(image, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jDesktopPane1.setLayer(image, javax.swing.JLayeredPane.DEFAULT_LAYER);

        attachImage.setText("Add Photo");
        attachImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                attachImageActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Search"));

        txtSearch.setToolTipText("Search employee id, name, surname");
        txtSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSearchActionPerformed(evt);
            }
        });
        txtSearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtSearchKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtSearch)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(updateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(printButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(30, 30, 30))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtPath, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(attachImage, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(0, 9, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jDesktopPane1)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(attachImage, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 506, Short.MAX_VALUE))
                .addGap(86, 86, 86)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(updateButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(printButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(63, 63, 63))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tableEmployeeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableEmployeeMouseClicked
        int row = tableEmployee.getSelectedRow();
        String tableClick = (tableEmployee.getModel().getValueAt(row, 0).toString());
        try{
         String sql = "SELECT Image FROM Employee where Employee_id = '"+tableClick+"' ";  
         pst = conn.prepareStatement(sql);
         rs = pst.executeQuery();
         
         if(rs.next()){
             byte[]imagedata = rs.getBytes("Image");
             format = new ImageIcon(imagedata);
             image.setIcon(format);
             
         }
         
        }
        catch(Exception e){
            e.printStackTrace();
        }
        
        try{
            
            String sql = "SELECT * FROM Employee where Employee_id='"+tableClick+"' ";
            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();
            if(rs.next()){
                String add1 = rs.getString("Employee_id");
                txtEmpID.setText(add1);
                
                String add2 = rs.getString("Name");
                txtEmpName.setText(add2);
                
                String add3 = rs.getString("Surname");
                txtEmpSurname.setText(add3);
                
                String add4 = rs.getString("Machine_name");
                txtEmpMachineName.setText(add4);
                
                String add5 = rs.getString("Machine_id");
                txtEmpMachineID.setText(add5);
                
                String add6 = rs.getString("Telephone");
                txtEmpTelNum.setText(add6);
                
                String add7 = rs.getString("Address");
                txtEmpAddrsNum.setText(add7);
            }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
    }//GEN-LAST:event_tableEmployeeMouseClicked

    private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
        txtEmpID.setText(null);
        txtEmpName.setText(null);
        txtEmpSurname.setText(null);
        txtEmpMachineName.setText(null);
        txtEmpMachineID.setText(null);
        txtEmpTelNum.setText(null);
        txtEmpAddrsNum.setText(null);
        txtPath.setText(null);
        image.setIcon(null);

    }//GEN-LAST:event_clearButtonActionPerformed

    private void homeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_homeButtonActionPerformed
        MainViewFrame mainFrame = new MainViewFrame();
        mainFrame.setVisible(true);
        dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_homeButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        try{
            String sql = "INSERT INTO Employee (Employee_id, Name, Surname, Machine_name, Machine_ID, Telephone, Address,Image) VALUES (?,?,?,?,?,?,?,?)";
            pst = conn.prepareStatement(sql);
            pst.setString(1, txtEmpID.getText());
            pst.setString(2, txtEmpName.getText());
            pst.setString(3, txtEmpSurname.getText());
            pst.setString(4, txtEmpMachineName.getText());
            pst.setString(5, txtEmpMachineID.getText());
            pst.setString(6, txtEmpTelNum.getText());
            pst.setString(7, txtEmpAddrsNum.getText());
            pst.setBytes(8, person_image);
            
            pst.execute();
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        
        finally {
        try{
        rs.close(); 
        pst.close(); }
        catch(Exception e) { } }
        
        Update_table();
    }//GEN-LAST:event_saveButtonActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        int p = JOptionPane.showConfirmDialog(null, "Do you really want to delete?","Delete", JOptionPane.YES_NO_OPTION);
        if(p==0){
        String sql = "DELETE FROM Employee where Employee_id=?";
        try{
            pst = conn.prepareStatement(sql);
            
            pst.setString(1, txtEmpID.getText());
            
            pst.execute();
            
            txtEmpID.setText(null);
            txtEmpName.setText(null);
            txtEmpSurname.setText(null);
            txtEmpMachineName.setText(null);
            txtEmpMachineID.setText(null);
            txtEmpTelNum.setText(null);
            txtEmpAddrsNum.setText(null);
            image.setIcon(null);
            
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        
        finally {
        try{
        rs.close(); 
        pst.close(); }
        catch(Exception e) { } }
        
        Update_table();
        }
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateButtonActionPerformed
        try{
            String value1 = txtEmpID.getText();
            String value2 = txtEmpName.getText();
            String value3 = txtEmpSurname.getText();
            String value4 = txtEmpMachineName.getText();
            String value5 = txtEmpMachineID.getText();
            String value6 = txtEmpTelNum.getText();
            String value7 = txtEmpAddrsNum.getText();
            
            String sql = "UPDATE Employee SET Employee_id = '"+value1+"',  Name = '"+value2+"', Surname = '"+value3+"', Machine_name = '"+value4+"', Machine_id = '"+value5+"', Telephone = '"+value6+"', Address = '"+value7+"' where Employee_id = '"+value1+"' ";
            pst = conn.prepareStatement(sql);
            pst.executeUpdate();
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        
        finally {
        try{
        rs.close(); 
        pst.close(); }
        catch(Exception e) { } }
        
        Update_table();


    }//GEN-LAST:event_updateButtonActionPerformed

    private void txtEmpTelNumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEmpTelNumActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtEmpTelNumActionPerformed

    private void txtEmpNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEmpNameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtEmpNameActionPerformed

    private void txtSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSearchActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSearchActionPerformed

    private void txtSearchKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSearchKeyReleased
        try{
            String sql = "SELECT * FROM Employee where Name = ?";
            pst = conn.prepareStatement(sql);
            pst.setString(1, txtSearch.getText());
            rs = pst.executeQuery();
            
            if(rs.next()){
                String add1 = rs.getString("Employee_id");
                txtEmpID.setText(add1);
                
                String add2 = rs.getString("Name");
                txtEmpName.setText(add2);
                
                String add3 = rs.getString("Surname");
                txtEmpSurname.setText(add3);
                
                String add4 = rs.getString("Machine_name");
                txtEmpMachineName.setText(add4);
                
                String add5 = rs.getString("Machine_id");
                txtEmpMachineID.setText(add5);
                
                String add6 = rs.getString("Telephone");
                txtEmpTelNum.setText(add6);
                
                String add7 = rs.getString("Address");
                txtEmpAddrsNum.setText(add7);
                
            }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        
        try{
            String sql = "SELECT * FROM Employee where Surname = ?";
            pst = conn.prepareStatement(sql);
            pst.setString(1, txtSearch.getText());
            rs = pst.executeQuery();
            
            if(rs.next()){
                String add1 = rs.getString("Employee_id");
                txtEmpID.setText(add1);
                
                String add2 = rs.getString("Name");
                txtEmpName.setText(add2);
                
                String add3 = rs.getString("Surname");
                txtEmpSurname.setText(add3);
                
                String add4 = rs.getString("Machine_name");
                txtEmpMachineName.setText(add4);
                
                String add5 = rs.getString("Machine_id");
                txtEmpMachineID.setText(add5);
                
                String add6 = rs.getString("Telephone");
                txtEmpTelNum.setText(add6);
                
                String add7 = rs.getString("Address");
                txtEmpAddrsNum.setText(add7);
                
            }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        
        try{
            String sql = "SELECT * FROM Employee where Employee_id = ?";
            pst = conn.prepareStatement(sql);
            pst.setString(1, txtSearch.getText());
            rs = pst.executeQuery();
            
            if(rs.next()){
                String add1 = rs.getString("Employee_id");
                txtEmpID.setText(add1);
                
                String add2 = rs.getString("Name");
                txtEmpName.setText(add2);
                
                String add3 = rs.getString("Surname");
                txtEmpSurname.setText(add3);
                
                String add4 = rs.getString("Machine_name");
                txtEmpMachineName.setText(add4);
                
                String add5 = rs.getString("Machine_id");
                txtEmpMachineID.setText(add5);
                
                String add6 = rs.getString("Telephone");
                txtEmpTelNum.setText(add6);
                
                String add7 = rs.getString("Address");
                txtEmpAddrsNum.setText(add7);
                
            }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        finally {
        try{
        rs.close(); 
        pst.close(); }
        catch(Exception e) { } }
    }//GEN-LAST:event_txtSearchKeyReleased

    private void tableEmployeeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableEmployeeKeyPressed

        
    }//GEN-LAST:event_tableEmployeeKeyPressed

    private void printButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printButtonActionPerformed
        MessageFormat header = new MessageFormat("Report Print");
        MessageFormat footer = new MessageFormat("Page{0, number, integer}");
        
        try{
            tableEmployee.print(JTable.PrintMode.NORMAL, header, footer);
        }
        catch(java.awt.print.PrinterException e){
            System.err.format("Cannot print %s%n", e.getMessage());
        }
        

    }//GEN-LAST:event_printButtonActionPerformed

    private void attachImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_attachImageActionPerformed
        
        JFileChooser chooser = new JFileChooser();
        chooser.showOpenDialog(null);
        File f = chooser.getSelectedFile();
        filename = f.getAbsolutePath();
        
        txtPath.setText(filename);
        
        try{
            File image = new File(filename);
            FileInputStream fis = new FileInputStream(image);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            for(int readNum; (readNum=fis.read(buf))!=-1;){
                bos.write(buf,0,readNum);
                
            }
            person_image = bos.toByteArray();
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        
        
    }//GEN-LAST:event_attachImageActionPerformed

    private void tableEmployeeKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableEmployeeKeyReleased
if(evt.getKeyCode()==KeyEvent.VK_DOWN || evt.getKeyCode()==KeyEvent.VK_UP){
            try{
            int row = tableEmployee.getSelectedRow();
            String tableClick = (tableEmployee.getModel().getValueAt(row, 0).toString());
            String sql = "SELECT * FROM Employee where Employee_id='"+tableClick+"' ";
            pst = conn.prepareStatement(sql);
            rs = pst.executeQuery();
            if(rs.next()){
                String add1 = rs.getString("Employee_id");
                txtEmpID.setText(add1);
                
                String add2 = rs.getString("Name");
                txtEmpName.setText(add2);
                
                String add3 = rs.getString("Surname");
                txtEmpSurname.setText(add3);
                
                String add4 = rs.getString("Machine_name");
                txtEmpMachineName.setText(add4);
                
                String add5 = rs.getString("Machine_id");
                txtEmpMachineID.setText(add5);
                
                String add6 = rs.getString("Telephone");
                txtEmpTelNum.setText(add6);
                
                String add7 = rs.getString("Address");
                txtEmpAddrsNum.setText(add7);
                
                
            }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
            finally {
            try{
            rs.close(); 
            pst.close(); }
            catch(Exception e) { } }
        }    }//GEN-LAST:event_tableEmployeeKeyReleased

    public void CurrentDate(){
       Thread clock =new Thread(){
       public void run(){
           for(;;){
        Calendar cal = new GregorianCalendar();
        int month = cal.get(Calendar.MONTH);
        int day = cal.get(Calendar.DAY_OF_MONTH);
        int year = cal.get(Calendar.YEAR);
        lbl_date.setText("Date "+day+"/"+(month+1)+"/"+year);
        
       int second = cal.get(Calendar.SECOND);
       int minute = cal.get(Calendar.MINUTE);
       int hour = cal.get(Calendar.HOUR_OF_DAY);
       lbl_time.setText("Time "+hour+":"+minute+":"+second);
               try {
                   sleep(1000);
               } catch (InterruptedException ex) {
                   Logger.getLogger(MainViewFrame.class.getName()).log(Level.SEVERE, null, ex);
               }
           }
       }
       
       };
        clock.start();
    }
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EmployerViewFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EmployerViewFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EmployerViewFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EmployerViewFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EmployerViewFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton attachImage;
    private javax.swing.JButton clearButton;
    private javax.swing.JButton deleteButton;
    private javax.swing.JButton homeButton;
    private javax.swing.JLabel image;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lbl_date;
    private javax.swing.JLabel lbl_time;
    private javax.swing.JButton printButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JTable tableEmployee;
    private javax.swing.JTextField txtEmpAddrsNum;
    private javax.swing.JTextField txtEmpID;
    private javax.swing.JTextField txtEmpMachineID;
    private javax.swing.JTextField txtEmpMachineName;
    private javax.swing.JTextField txtEmpName;
    private javax.swing.JTextField txtEmpSurname;
    private javax.swing.JTextField txtEmpTelNum;
    private javax.swing.JTextField txtPath;
    private javax.swing.JTextField txtSearch;
    private javax.swing.JButton updateButton;
    // End of variables declaration//GEN-END:variables

private ImageIcon format = null;
String filename = null;
int s=0;
byte[] person_image = null;
}
